package com.longxi.tianjintianbao.ui.activity.houseinspection;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.longxi.tianjintianbao.AppConst;
import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.ui.base.BaseActivity;
import com.longxi.tianjintianbao.ui.presenter.houseinspection.AssetsCheckAtPresenter;
import com.longxi.tianjintianbao.ui.view.houseinspection.IAssetsCheckAtView;

import butterknife.BindView;

/**
 * 入住验房里面有一个个小项目 这些项目都可以点击查看或检查 这个是检查用 //ps有卵用 接口完全不按原型图搞 写个垃圾
 * Created by cxw on & 2018/9/20
 */
public class AssetsCheckActivity extends BaseActivity<IAssetsCheckAtView, AssetsCheckAtPresenter> implements IAssetsCheckAtView {

    @BindView(R.id.tvAssetsLeft)
    TextView mTvAssetsLeft;
    @BindView(R.id.tvAssetsRight)
    TextView mTvAssetsRight;
    @BindView(R.id.rgState)
    RadioGroup mRgState;
    @BindView(R.id.etExplain)
    EditText mEtExplain;
    @BindView(R.id.recyclerView)
    RecyclerView mRecyclerView;
    @BindView(R.id.tvValue)
    TextView mTvValue;
    @BindView(R.id.btnSubmit)
    Button mBtnSubmit;

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_assets_check;
    }

    @Override
    protected AssetsCheckAtPresenter createPresenter() {
        return new AssetsCheckAtPresenter(this);
    }

    @Override
    public void initView() {
        super.initView();
        mPresenter.initView();
        mPresenter.initSelectImage(mRecyclerView, 3);
    }

    @Override
    public void initData() {
        super.initData();
        String checker = getIntent().getStringExtra(AppConst.CHECKER);
        String checkdept = getIntent().getStringExtra(AppConst.CHECKDEPT);
        String checkdate = getIntent().getStringExtra(AppConst.CHECKDATE);
        String name = getIntent().getStringExtra(AppConst.NAME);
        String type = getIntent().getStringExtra(AppConst.TYPE);
        String code = getIntent().getStringExtra(AppConst.CODE);
        String state = getIntent().getStringExtra(AppConst.STATE);

        mTvAssetsLeft.setText("资产名称:" + name +
                "\n资产编号:" + code);
        if(type.equals("0")){
            mTvAssetsRight.setText("资产类别:资产");
        }else if(type.equals("1")){
            mTvAssetsRight.setText("资产类别:设施");
            mRecyclerView.setVisibility(View.GONE);
        }

        mTvValue.setText("验  房  人:" + checker +
                "\n验房部门:" + checkdept +
                "\n验房日期:" + checkdate);

        if(state.equals("破损")){
            mPresenter.state = "破损";
            mRgState.check(R.id.rbtnAbnormal);
        }else{
            mPresenter.state = "正常";
            mRgState.check(R.id.rbtnNormal);
        }

        String yflx = getIntent().getStringExtra(AppConst.YFLX);

        if(yflx.equals(AppConst.YAN_FANG_RUZHU)){
            setTitle("入住验房");
            mBtnSubmit.setOnClickListener(v -> mPresenter.checkInSave());
        }else if(yflx.equals(AppConst.YAN_FANG_TUIZHU)){
            setTitle("退住验房");
            mBtnSubmit.setOnClickListener(v -> mPresenter.checkOutSave());
        }
    }

    @Override
    public void initListener() {
        super.initListener();
        mRgState.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if(checkedId == R.id.rbtnNormal){
                    mPresenter.state = "正常";
                }else{
                    mPresenter.state = "破损";
                }
            }
        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_OK) {
            return;
        }
        mPresenter.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public RadioGroup getRgState() {
        return mRgState;
    }

    @Override
    public EditText getEtExplain() {
        return mEtExplain;
    }

    @Override
    public TextView getTvValue() {
        return mTvValue;
    }

    @Override
    public Button getBtnSubmit() {
        return mBtnSubmit;
    }

    @Override
    public RecyclerView getRecyclerView() {
        return mRecyclerView;
    }
}
